<html>
<head>
    <title>流程发布管理</title>
    <#include "/common/import.ftl" >
    <script>
        $(function () {
            $('#lockList').datagrid({
                title: '访问资源列表',
                url: "${ctx}/uct/lock/lock!data.action?sysId=${sysId!''}",
                loadMsg: '数据载入中，请稍后……',
                nowrap: false,
                collapsible: false,
                fitColumns: true,
                pagination: true,
                singleSelect: true,
                rownumbers: true,
                remoteSort: false,
                pageList: [10, 15, 20, 50],
                idField: 'lockId',
                frozenColumns: [[{
                    title: '资源名称',
                    field: 'lockCname',
                    width: 200,
                    formatter: function (value) {
                        return '<span style="color:blue">' + value + '</span>';
                    }
                }]],
                columns: [[{
                    field: 'lockPath',
                    title: '资源路径',
                    width: 220,
                    sorter: function (a, b) {
                        return (a > b ? 1 : -1);
                    }
                }, {
                    field: 'lockType',
                    title: '资源类型',
                    width: 80,
                    formatter: function (value) {
                        if ('Family' == value) {
                            return '家族锁';
                        } else if ('Father' == value) {
                            return '父辈锁';
                        } else if ('Child' == value) {
                            return '子孙锁';
                        } else if ('Strick' == value) {
                            return '严格锁';
                        }
                    }
                }, {
                    field: 'actFullEname',
                    title: '对应权限',
                    width: 120,
                    sorter: function (a, b) {
                        return (a > b ? 1 : -1);
                    }
                }, {
                    field: 'lockStatus',
                    title: '当前状态',
                    width: 80,
                    formatter: function (value) {
                        if (value == '1') {
                            return '<font color=blue>启用</font>';
                        } else if (value == '0') {
                            return '<font color=red>停用</font>';
                        } else {
                            return '';
                        }

                    }
                }, {
                    field: 'sysCname',
                    title: '所属系统',
                    width: 180
                }]],

                toolbar: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        addLock();
                    }

                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        editLock();
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-cut',
                    handler: function () {
                        delLock();
                    }
                }, '-',

                    {
                        text: '刷新',
                        iconCls: 'icon-reload',
                        handler: function () {
                            reload('');
                        }
                    }],
                onDblClickRow: function (row) {
                    editLock();
                }
            });
        });

        function delLock() {
            var node = getSelected();
            if (node) {
                $.messager.confirm('确认', '您确定要删除:<font color="red">' + node.lockCname + '</font> ？',
                        function (r) {
                            if (r) {
                                $.ajax({
                                    type: "post",
                                    url: "${ctx}/uct/lock/del.action?id=" + node.lockId,
                                    success: function (data, textStatus) {
                                        var result = jQuery.parseJSON(data);
                                        if (result.flag == "T") {
                                            $.messager.alert('结果', '操作成功', 'info');
                                            var rowIndex = $('#lockList').datagrid('getRowIndex', node);
                                            $('#lockList').datagrid('deleteRow', rowIndex);
                                            reload();
                                        } else {
                                            $.messager.alert('提交结果', result.msg, 'error');
                                        }
                                    }
                                });
                            }
                        });
            }

        }

        function editLock() {
            var node = getSelected();
            if (node) {
                $('#lockAddFrame').html('');
                var url = '${ctx}/uct/lock/add.action?id=' + node.lockId + "&sysEname=${sysEname!''}";
                $('#lockAddFrame').attr("src", url);
                $('#lockAddWin').window('open');
            }
        }

        function closeAddWin() {
            $('#lockAddWin').window('close');
        }

        function addLock() {
            $('#lockAddFrame').html('');
            var url = "${ctx}/uct/lock/add.action?sysId=${sysId!''}&sysEname=${sysEname!''}";
            $('#lockAddFrame').attr("src", url);
            $('#lockAddWin').window('open');
        }

        function getSelected() {
            var selected = $('#lockList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        function reload() {
            $('#lockList').datagrid('reload');
        }

        function lockQuery() {
            var queryParams = $('#lockList').datagrid('options').queryParams;
            queryParams.lockCname = $('#lockCname').val();
            queryParams.lockPath = $('#lockPath').val();
            queryParams.actFullEname = $('#actFullEname').val();
            queryParams.lockStatus = $('#lockStatus').val();
            var options = $('#lockList').datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            options.total = 0;
            options.pageSize = 10;
            reload();
        }

        function clearQuery() {
            $('#lockCname').val('');
            $('#lockPath').val('');
            $('#actFullEname').val('');
            lockQuery();
        }


    </script>
</head>

<body>
<table class="planel-body">
    <tr>
        <td>资源名称</td>
        <td>
            <input name="lockCname" id="lockCname" value=""/>
        </td>
        <td>资源路径</td>
        <td>
            <input name="lockPath" id="lockPath" value=""/>
        </td>
        <td>资源状态</td>
        <td>
            <select name="lockStatus" id="lockStatus" style="width:50px;">
                <option value="">全部</option>
                <option value="1">启用</option>
                <option value="0"/>
                禁用</option>
            </select>
        </td>
        <td>
            <a class="easyui-linkbutton" iconCls="icon-search"
               onclick="lockQuery();">查询</a>
            <a class="easyui-linkbutton" iconCls="" onclick="clearQuery();">清空</a>
        </td>
    </tr>
</table>


<table id="lockList"></table>
<center><a class="easyui-linkbutton" iconCls=""
           onclick="window.location.href='${ctx}/uct/sys/lock-sys-list.action'">返回</a></center>
<div id="lockAddWin" class="easyui-window" title="访问控制"
     style="padding: 5px; width: 560px; height: 250;"
     iconCls="icon-search" closed="true" maximizable="false"
     minimizable="false" collapsible="false">
    <iframe frameborder="0" id="lockAddFrame" height="100%" width="100%"
            scrolling="yes" frameborder="0"></iframe>
</div>

</body>
</html>